package com.example.yuejian21.nongfusanquan.yuejian21.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.yuejian21.nongfusanquan.yuejian21.R;
import com.example.yuejian21.nongfusanquan.yuejian21.adapter.GiftAdapter;
import com.example.yuejian21.nongfusanquan.yuejian21.adapter.MatchAdapter;
import com.example.yuejian21.nongfusanquan.yuejian21.javabean.Giftbean;
import com.example.yuejian21.nongfusanquan.yuejian21.javabean.Matchbean;
import com.example.yuejian21.nongfusanquan.yuejian21.model.Giftmodel;
import com.example.yuejian21.nongfusanquan.yuejian21.model.Matchmodel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Nongfusanquan on 2017-10-27.
 */

public class GiftFragment extends Fragment {
    private RecyclerView recyclerView;
    private TextView activitytitle;
    private View view=null;



            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        view= inflater.inflate(R.layout.fragment_gift, container, false);
        recyclerView=(RecyclerView)view.findViewById(R.id.rv);
        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(staggeredGridLayoutManager);
        recyclerView.setItemAnimator(new DefaultItemAnimator());//设置添加,移除item的动画,DefaultItemAnimator为默认的





        getData();
        return view;
    }



    private void getData() {
        Giftmodel activitymodel=new Giftmodel();
        Call<List<Giftbean>> call=activitymodel.getgiftlist();
        call.enqueue(new Callback<List<Giftbean>>() {
            @Override
            public void onResponse(Call<List<Giftbean>> call, Response<List<Giftbean>> response) {
                List<Giftbean> data = response.body();  //获取数据
                recyclerView.setAdapter(new GiftAdapter(GiftFragment.this.getActivity(), data));


            }

            @Override
            public void onFailure(Call<List<Giftbean>> call, Throwable t) {

            }
        });

    }
}
